package org.example.spring.ioc.config;

import org.example.spring.ioc.bean.Dog;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnResource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;

/*
* @Scope 调整组建的作用域
* 1、@Scope("prototype")：非单实例
* 2、@Scope("singleton")：单实例
* 3、@Scope("request")：同一个请求单实例
* 4、@Scope("session")：同一次会话单实例
*/

@Configuration
public class DogConfiguration {
    @ConditionalOnResource(resources = "classpath:dog.txt")
    //@Scope("prototype")//创建prototype(多实例)作用域的bean
    @Lazy//懒加载: 容器启动时不创建对象，第一次使用对象时创建对象
    @Bean
    public Dog dog(){
        Dog dog = new Dog();
        return dog;
    }
}
